import { request } from '@umijs/max';

export async function login(options) {
  return request('public/admin/login', {
    method: 'post',
    // headers: {
    //   'Content-Type': 'application/json',
    // },
    responseInterceptors: [
      (response) => {
        const { data = {} } = response;
        // const { AccessToken } = data;
        console.log(data, 'dddd');
        if (data?.data?.AccessToken) {
          localStorage.setItem('token', data.data.AccessToken);
        }
        if (data?.data?.user) {
          localStorage.setItem('user', JSON.stringify(data.data.user));
        }

        // do something
        return response;
      },
    ],
    ...(options || {}),
  });
}

// 127.0.0.1:17256v1/public/captcha
/** 获取当前的用户 GET /currentUser */
export async function currentUser() {
  return new Promise((resolve) => {
    const user = localStorage.getItem('user');
    resolve(JSON.parse(user));
  });
  // return request('base/currentUser', {
  //   method: 'GET',
  // });
}
